package cn.tedu.ivos.dict.controller;

import cn.tedu.ivos.base.response.JsonResult;
import cn.tedu.ivos.dict.pojo.dto.DictQuery;
import cn.tedu.ivos.dict.pojo.dto.DictSaveParam;
import cn.tedu.ivos.dict.pojo.vo.DictVO;
import cn.tedu.ivos.dict.service.DictService;
import cn.tedu.ivos.dictoption.pojo.vo.DictoptionVO;
import cn.tedu.ivos.dictoption.service.DictoptionService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Tag(name="字典模块")
@RestController
@RequestMapping("/v1/dict/")
public class DictController {
    @Autowired
    DictService dictService;
    @Autowired
    DictoptionService dictoptionService;

    @GetMapping("select")
    @Operation(summary = "查询字典")
    @ApiOperationSupport(order = 10)
    public JsonResult selectDict(DictQuery query){
        log.debug("查询字典："+query);
        List<DictVO> list =dictService.selectDict(query);
        return JsonResult.ok(list);
    }

    @PostMapping("save")
    @Operation(summary = "新增字典")
    @ApiOperationSupport(order = 20)
    public JsonResult saveDict( @Validated DictSaveParam param){
        log.debug("新增字典："+param);
        dictService.saveDict(param);
        return JsonResult.ok();
    }


    @PostMapping("delete")
    @Operation(summary = "删除字典")
    @ApiOperationSupport(order = 30)
    public JsonResult deleteDict( Long id){
        log.debug("删除字典："+id);
        dictService.deleteDict(id);
        return JsonResult.ok();
    }


}
